package org.itboys.commons.utils.tools;

import javax.servlet.http.HttpServletResponse;

import org.itboys.commons.dto.ResultPageDOHelper;
import org.itboys.commons.utils.ajax.AjaxUtils;


/**
 * @author tjc
 */
public class ResponseManager {
	public static void SystemError(HttpServletResponse response) {
		SystemError(response, null);
	}
	public static void SystemError(HttpServletResponse response, String callback) {

		AjaxUtils.renderJsonporJson(response, callback,
				ResultPageDOHelper.getErrorResultDO(-1, "系统异常！"));
	}
	public static void normalSuccess(HttpServletResponse response) {
		normalSuccess(response, null);
	}
	public static void normalSuccess(HttpServletResponse response,
			String callback) {
		AjaxUtils.renderJsonporJson(response, callback,
				ResultPageDOHelper.getMsgResultDO(1, "成功！"));
	}
	public static <T> void normalResult(T t, HttpServletResponse response) {
		normalResult(t, response, null);
	}
	public static <T> void normalResult(T t, HttpServletResponse response,
			String callback) {
		AjaxUtils.renderJsonporJson(response, callback,
				ResultPageDOHelper.getMsgResultDO(t, "成功！"));
	}

	public static void ErrorParam(HttpServletResponse response, String callback) {
		AjaxUtils.renderJsonporJson(response, callback,
				ResultPageDOHelper.getErrorResultDO(-100, "参数不全或传参不合法！"));
	}

	public static void PermissionError(HttpServletResponse response,
			String callback) {
		AjaxUtils.renderJsonporJson(response, callback,
				ResultPageDOHelper.getErrorResultDO(-101, "对不起，您没有该权限！"));
	}

	public static void StatusError(HttpServletResponse response, String callback) {
		AjaxUtils.renderJsonporJson(response, callback,
				ResultPageDOHelper.getErrorResultDO(-102, "对不起，该状态已更改！"));
	}

	public static void DuplicateOprationError(HttpServletResponse response,
			String callback) {
		AjaxUtils.renderJsonporJson(response, callback,
				ResultPageDOHelper.getErrorResultDO(-103, "对不起，不能重复操作！"));
	}
	public static void NullError(HttpServletResponse response) {
		NullError(response, null);
	}
	public static void NullError(HttpServletResponse response, String callback) {
		AjaxUtils.renderJsonporJson(response, callback,
				ResultPageDOHelper.getErrorResultDO(-104, "对不起，没有合适的对象！"));
	}

	public static void UnEnoughError(HttpServletResponse response,
			String callback) {
		AjaxUtils.renderJsonporJson(response, callback,
				ResultPageDOHelper.getErrorResultDO(-105, "对不起，支付金额不足！"));
	}

	public static void ProcessingError(HttpServletResponse response,
			String callback) {
		AjaxUtils.renderJsonporJson(response, callback,
				ResultPageDOHelper.getErrorResultDO(-106, "对不起，正在处理中！"));
	}

	public static void OverdueError(HttpServletResponse response,
			String callback) {
		AjaxUtils.renderJsonporJson(response, callback,
				ResultPageDOHelper.getErrorResultDO(-107, "对不起，操作已过期！"));
	}

	public static void ValiError(HttpServletResponse response, String callback) {
		AjaxUtils.renderJsonporJson(response, callback,
				ResultPageDOHelper.getErrorResultDO(-108, "对不起，校验失败！"));
	}
	public static void NoAccount(HttpServletResponse response, String callback) {
		AjaxUtils.renderJsonporJson(response, callback,
				ResultPageDOHelper.getErrorResultDO(-109, "对不起，用户未登录或不存在！"));
	}
	public static void AccountOverDue(HttpServletResponse response, String callback) {
		AjaxUtils.renderJsonporJson(response, callback,
				ResultPageDOHelper.getErrorResultDO(-110, "对不起，账号已过期！"));
	}
	public static void CustomizedError(HttpServletResponse response,String content) {
		AjaxUtils.renderJsonporJson(response, null,
				ResultPageDOHelper.getErrorResultDO(-200, content));
	}
	public static void CustomizedError(HttpServletResponse response,
			String content, String callback) {
		AjaxUtils.renderJsonporJson(response, callback,
				ResultPageDOHelper.getErrorResultDO(-200, content));
	}
}
